
<?php
if ($leave_record > 0) {
	$page = $this->uri->segment(4);
	$page = $page ? $page : 0;
	echo form_open();
	$this->load->view('incs/num_perpage');
	?>
	<table class="display" id="search">
		<thead>
			<tr class="success">
				<th>N&ordm;</th>
				<th><?php echo form_checkbox(array('name' => 'checker', 'id' => 'check_header')); ?></th>
				<th>Staff Name</th>
				<th>Gender</th>
				<th>Type of Leave</th>
				<th>Reason</th>
				<th>Start Date</th>
				<th>End Date</th>
				<th>Duration</th>
				<th>Pending</th>
			</tr>
		</thead>
		<tbody>
			<?php
			// column id
			$id = 1;
			if ($this->uri->segment(4)) {
				$id = $this->uri->segment(4) + 1;
			} else {
				$id = 1;
			}
			foreach ($leave_record as $data):
				//duration of leaving think as Day
				$duration = $data->duration;
				if ($duration > 1) {
					$day = 'Days';
				} else {
					$day = 'day';
				}
				/* Display as Month	 * uss substr() to trim string for database of date */
				$str_date = substr($data->start_date, 6, -3);
				$months = array('January', 'February', 'Match', 'April', 'May', 'June', 'July', 'Auegst', 'September', 'October', 'November', 'December');
				for ($i = 0; $i < count($months); $i++) {
					if ($i == $str_date) {
						$month = $months[$i];
					}
				}
				?>
				<tr class="greadU">
					<td class="center"><?php echo $id++; ?></td>
					<td class="center"><?php echo form_checkbox(array('class' => 'check_value', 'name' => 'check[]'), $data->rcd_id); ?>
					</td>
					<td class="center"><?php echo ucfirst($data->emp_fname) . ' ' . strtoupper($data->emp_lname); ?></td>
					<td class="center"><?php echo $data->emp_gender; ?></td>
					<td class="center"><?php echo $data->lea_name; ?></td>			

					<td class="center"><?php echo $data->lea_reason; ?></td>
					<td class="center"><?php echo $data->start_date; ?></td>
					<td class="center"><?php echo $data->end_date; ?></td>
					<td class="center"><?php echo $duration . nbs() . $day; ?></td>
					<td class="center">
						
<!--					Manager -->
						<?php
						$del = img('bootstrap/images/del.png');
						$del_annual = anchor('manager/delete_before_approve/' . $data->lea_id . '/' . $data->rcd_id, $del, 'title="Delete" onclick="return confirm(\'Are you sure want to delete?\');"');
						$del_catchup = anchor('manager/delete_before_approve/' . $data->lea_id . '/' . $data->rcd_id . '/' . $data->desc_id, $del, 'title="Delete" onclick="return confirm(\'Are you sure want to delete?\');"');
						if ($data->lea_id == 1) {
							echo anchor('manager/approval/type_pending/' . $data->rcd_status . '/' . $data->rcd_id, img('bootstrap/images/notice.png'), 'title="Approve"').' | '. $del_annual;
						} else if ($data->lea_id == 2) {
							echo anchor('manager/approval/type_pending/' . $data->rcd_status . '/' . $data->rcd_id, img('bootstrap/images/notice.png'), 'title="Approve"').' | '. $del_catchup;
						}
						?>
					</td>

				</tr>
				<?php
			endforeach;
			?></tbody>
	</table>

	<table>
		<tr>
			<td ></td>
			<?php
			if ($pagination) {
				?>

				<td>
					<span class="pagination-link"><?php echo $pagination; ?></span>
				</td>
			</tr>
			<?php
		}
		?>

	</table>
	<table>
		<tr>
			<td>
				<?php echo form_submit('approve', 'Approve', 'class="btn btn-info"'); ?>
			</td>
		</tr>
	</table>
	<?php
	if (isset($_POST['approve'])) {
		if (isset($_POST['check'])) {
			foreach ($_POST['check'] as $value) {
				$sql = "UPDATE pnc_record SET rcd_status = 1 WHERE rcd_id =$value";

				mysql_query($sql) or die(mysql_error());
			}
			?>
			<script>alert('Successful for approve !!!');</script>
			<?php
		} else {
			?>

			<script>alert('Please click on button check first !!!');</script>
			<?php
		}
		echo '<meta http-equiv="refresh" content="0">';
	}
	echo form_close();
} else {
	?>
	<table>
		<tr>
			<td><?php echo "No Employee Request Leaving!!"; ?></td>
		</tr>
	</table>
<?php } ?>
